package com.nervenets.web.controller.handler.user;

import com.nervenets.utils.StringUtils;
import com.nervenets.web.entity.UserToken;
import com.nervenets.web.enumeration.AuthStatus;
import com.nervenets.web.enumeration.Gender;
import com.nervenets.web.hibernate.domain.user.User;
import com.nervenets.web.hibernate.domain.user.UserRole;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Created by Joe on 2018/1/6.
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserModel {
    private long id;
    private String code;
    private long inviteUserId;
    private String token;
    private String mobile;
    private String disableReason;
    private String name;
    private String idNumber;
    private String frontOfId;
    private String backOfId;
    private String failedReason;
    private int areaId;
    private String avatar;
    private Gender gender;
    private int disable;
    private long money;
    private String wechatId;
    private int createTime;
    private UserRole role;
    private AuthStatus authStatus;
    private int authTime;
    private int totalProject;
    private long surplus;
    private long score;
    private long reward;
    private boolean special;

    public UserModel(User user, int tokenType, String defaultAvatar) {
        this.id = user.getId();
        this.code = user.getCode();
        this.inviteUserId = user.getInviteUserId();
        this.token = new UserToken(user.getId(), tokenType).getTokenStr();
        this.mobile = user.getMobile();
        this.disableReason = user.getInfo().getDisableReason();
        this.name = StringUtils.isEmpty(user.getInfo().getName()) ? String.format("用户%s", this.id) : user.getInfo().getName();
        this.idNumber = user.getInfo().getIdNumber();
        this.frontOfId = user.getInfo().getFrontOfId();
        this.backOfId = user.getInfo().getBackOfId();
        this.failedReason = user.getInfo().getFailedReason();
        this.areaId = user.getAreaId();
        this.avatar = StringUtils.isEmpty(user.getAvatar()) ? defaultAvatar : user.getAvatar();
        this.gender = user.getGender();
        this.disable = user.getDisable();
        this.wechatId = user.getWechatId();
        this.createTime = user.getCreateTime();
        this.role = user.getRole();
        this.authStatus = user.getAuthStatus();
        this.authTime = user.getAuthTime();
        this.special = user.isSpecial();
    }
}
